package com.xq.jltx.ffmpegsinglecmd;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.xq.jltx.commonassert.task.AssertReleaseTask;
import com.xq.jltx.ffmpeg.FFmpegCmd;

public class MainActivity extends AppCompatActivity implements AssertReleaseTask.ReleaseCallback{
    private TextView btnTransfer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnTransfer = (TextView) findViewById(R.id.btn_transfer);
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        AssertReleaseTask videoReleaseTask = new AssertReleaseTask(this, "input.mp4", this);
//        AsyncTaskCompat.executeParallel(videoReleaseTask);
        videoReleaseTask.execute();
    }

    @Override
    public void onReleaseSuccess(String filePath) {
        btnTransfer.setEnabled(true);
    }

    public void onCmdClick(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String filePath = getExternalFilesDir(null).getAbsolutePath();
                String cmdline = String.format("ffmpeg -d -i %s/input.mp4 %s/output.mkv", filePath, filePath);
                String[] argv = cmdline.split(" ");
                Integer argc = argv.length;
                FFmpegCmd.exec(argc, argv);
            }
        }).start();
    }
}
